package com.myphoto.base.log.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.myphoto.base.annotation.ProductSwagger;
import com.myphoto.base.annotation.SysLog;
import com.myphoto.base.enumtype.LogTypeEnum;
import com.myphoto.base.enumtype.ModuleEnum;
import com.myphoto.base.enumtype.MsgEnum;
import com.myphoto.base.log.service.LogService;
import com.myphoto.base.log.vo.P6spyLogVO;
import com.myphoto.base.log.vo.SysLogVO;
import com.myphoto.base.log.vo.UrlLogVO;
import com.myphoto.base.mybatis.log.entity.TbLogP6spyEntity;
import com.myphoto.base.mybatis.log.entity.TbLogSysEntity;
import com.myphoto.base.mybatis.log.entity.TbLogUrlEntity;
import com.myphoto.base.util.Groups;
import com.myphoto.base.util.PageParam;
import com.myphoto.base.util.R;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/log")
@Api(tags = "日志管理")
public class LogController {

    @Autowired
    private LogService logService;

    /**
    * @description 查询系统日志列表
    * @author 方安伦
    * @date 2021/12/14 11:01
     **/
    @ApiOperation(value = "查询系统日志列表", notes = "查询系统日志列表",httpMethod="POST")
    @ApiOperationSupport( author = "方安伦",ignoreParameters = {"id"})
    @ProductSwagger
    @RequestMapping("/loadSysLogList")
    @SysLog(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询系统日志列表")
    public R<TbLogSysEntity> loadSysLogList(@Validated PageParam pageParam, @Validated SysLogVO sysLogVO) throws Exception{
        Page<TbLogSysEntity> page = new Page<>(pageParam.getCurrent(),pageParam.getLimit());
        IPage<TbLogSysEntity> logIPage = logService.loadSysLogList(page,sysLogVO);
        return R.success(MsgEnum.QUERY_SUCCESS,logIPage);
    }

    /**
    * @description 查询P6spy日志列表
    * @author 方安伦
    * @date 2021/12/16 9:24
     **/
    @ApiOperation(value = "查询P6spy日志列表", notes = "查询P6spy日志列表",httpMethod="POST")
    @ApiOperationSupport( author = "方安伦",ignoreParameters = {"id"})
    @ProductSwagger
    @RequestMapping("/loadP6spyLogList")
    @SysLog(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询P6spy日志列表")
    public R<TbLogP6spyEntity> loadP6spyLogList(@Validated PageParam pageParam, @Validated P6spyLogVO p6spyLogVO) throws Exception{
        Page<TbLogP6spyEntity> page = new Page<>(pageParam.getCurrent(),pageParam.getLimit());
        IPage<TbLogP6spyEntity> logIPage = logService.loadP6spyLogList(page,p6spyLogVO);
        return R.success(MsgEnum.QUERY_SUCCESS,logIPage);
    }

    /**
    * @description 查询Url日志列表
    * @author 方安伦
    * @date 2021/12/16 9:34
     **/
    @ApiOperation(value = "查询Url日志列表", notes = "查询Url日志列表",httpMethod="POST")
    @ApiOperationSupport( author = "方安伦",ignoreParameters = {"id"})
    @ProductSwagger
    @RequestMapping("/loadUrlLogList")
    @SysLog(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询Url日志列表")
    public R<TbLogUrlEntity> loadUrlLogList(@Validated PageParam pageParam, @Validated UrlLogVO urlLogVO) throws Exception{
        Page<TbLogUrlEntity> page = new Page<>(pageParam.getCurrent(),pageParam.getLimit());
        IPage<TbLogUrlEntity> logIPage = logService.loadUrlLogList(page,urlLogVO);
        return R.success(MsgEnum.QUERY_SUCCESS,logIPage);
    }

    /**
    * @description 查询系统日志详情
    * @author 方安伦
    * @date 2021/12/16 11:37
     **/
    @ApiOperation(value = "查询系统日志详情", notes = "查询系统日志详情",httpMethod="POST")
    @ApiOperationSupport( author = "方安伦",includeParameters = {"id"})
    @ProductSwagger
    @RequestMapping("/loadSysLogDetail")
    @SysLog(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询系统日志详情")
    public R<TbLogSysEntity> loadSysLogDetail(@Validated(Groups.QueryById.class) SysLogVO sysLogVO) throws Exception{
        TbLogSysEntity tbLogSysEntity = logService.loadSysLogDetail(sysLogVO.getId());
        return R.success(MsgEnum.QUERY_SUCCESS,tbLogSysEntity);
    }

    /**
    * @description 查询P6spy日志详情
    * @author 方安伦
    * @date 2021/12/16 11:42
     **/
    @ApiOperation(value = "查询P6spy日志详情", notes = "查询P6spy日志详情",httpMethod="POST")
    @ApiOperationSupport( author = "方安伦",includeParameters = {"id"})
    @ProductSwagger
    @RequestMapping("/loadP6spyLogDetail")
    @SysLog(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询P6spy日志详情")
    public R<TbLogP6spyEntity> loadP6spyLogDetail(@Validated(Groups.QueryById.class) P6spyLogVO p6spyLogVO) throws Exception{
        TbLogP6spyEntity tbLogP6spyEntity = logService.loadP6spyLogDetail(p6spyLogVO.getId());
        return R.success(MsgEnum.QUERY_SUCCESS,tbLogP6spyEntity);
    }

    /**
    * @description 查询Url日志详情
    * @author 方安伦
    * @date 2021/12/16 11:44
     **/
    @ApiOperation(value = "查询Url日志详情", notes = "查询Url日志详情",httpMethod="POST")
    @ApiOperationSupport( author = "方安伦",includeParameters = {"id"})
    @ProductSwagger
    @RequestMapping("/loadUrlLogDetail")
    @SysLog(model = ModuleEnum.LOG,logType = LogTypeEnum.INFO,value = "查询Url日志详情")
    public R<TbLogUrlEntity> loadUrlLogDetail(@Validated(Groups.QueryById.class) UrlLogVO urlLogVO) throws Exception{
        TbLogUrlEntity tbLogUrlEntity = logService.loadUrlLogDetail(urlLogVO.getId());
        return R.success(MsgEnum.QUERY_SUCCESS,tbLogUrlEntity);
    }
}
